package com.kkb.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.mapper.MedicinePeopleMapper;
import com.kkb.pojo.MedicinePeople;
import com.kkb.pojo.MedicinePeopleExample;
import com.kkb.pojo.PricePeople;
import com.kkb.pojo.PricePeopleExample;
import com.kkb.vo.MedicinePeopleInsertVO;
import com.kkb.vo.MedicinePeopleQueryVO;
import com.kkb.vo.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MedicinePeopleService {
    @Resource
    MedicinePeopleMapper mapper;

    public PageInfo queryAll(int index, int size, MedicinePeopleQueryVO vo) {
        MedicinePeopleExample example = new MedicinePeopleExample();
        MedicinePeopleExample.Criteria criteria = example.createCriteria();
        if (vo.getPeopleId() != null && !vo.getPeopleId().trim().equals(""))
            criteria.andBehIdEqualTo(Integer.parseInt(vo.getPeopleId().trim()));
        if (vo.getMedicineId() != null && !vo.getMedicineId().trim().equals(""))
            criteria.andDrIdEqualTo(Integer.parseInt(vo.getMedicineId().trim()));

        PageHelper.startPage(index, size);
        List<MedicinePeople> result = mapper.selectByExample(example);
        PageInfo pageInfo = new PageInfo(result);
        return pageInfo;
    }

    public int add(MedicinePeople medicinePeople) {
        return mapper.insertSelective(medicinePeople);
    }

    public List queryByPatientId(int id) {
        MedicinePeopleExample example = new MedicinePeopleExample();
        MedicinePeopleExample.Criteria criteria = example.createCriteria();

        criteria.andBehIdEqualTo(id);

        return mapper.selectByExample(example);
    }

    public int addByList(MedicinePeopleInsertVO vo) {
        return mapper.insertByList(vo);
    }
    public int update(MedicinePeople medicinePeople){
        return mapper.updateByPrimaryKeySelective(medicinePeople);
    }

    public MedicinePeople queryById(int id){
        return mapper.selectByPrimaryKey(id);
    }
}
